package com.cyss.greenball.main;

import com.cyss.greenball.util.ActivityUtil;
import com.cyss.greenball.util.SystemUtil;
import com.cyss.greenball.view.CreateMapView;
import com.lianzt.commondata.DataConvertFactory;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class CreateMapActivity extends BaseActivity {
	private CreateMapView cmv;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		cmv = new CreateMapView(this);
		setContentView(cmv);
	}

	@Override
	protected void init() {

	}

	@Override
	protected void setOnListener() {

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);

		menu.add(0, SystemUtil.GAME_ELEMENT_LINEBARRIER, 0, R.string.draw_line)
				.setShortcut('3', 'c');
		menu.add(0, SystemUtil.GAME_ELEMENT_RECTANGLEBARRIER, 0,
				R.string.draw_rec).setShortcut('4', 's');
		menu.add(0, SystemUtil.GAME_ELEMENT_TRAPHOLE, 0,
				R.string.draw_trap_hole).setShortcut('5', 'z');
		menu.add(0, SystemUtil.GAME_ELEMENT_DESTINYHOLE, 0,
				R.string.draw_destiny_hole).setShortcut('5', 'z');
		menu.add(0, SystemUtil.GAME_ELEMENT_GREENBALL, 0,
				R.string.draw_green_ball).setShortcut('5', 'z');
		menu.add(0, SystemUtil.GAME_ELEMENT_REVOKE, 0, R.string.revoke)
				.setShortcut('5', 'z');
		menu.add(0, SystemUtil.GAME_MAP_SAVE, 0, R.string.save).setShortcut(
				'5', 'z');
		menu.add(0, SystemUtil.GAME_TRY_PLAY, 0, R.string.try_play)
				.setShortcut('5', 'z');
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case SystemUtil.GAME_ELEMENT_LINEBARRIER:
			cmv.setElementType(item.getItemId());
			return true;
		case SystemUtil.GAME_ELEMENT_RECTANGLEBARRIER:
			cmv.setElementType(item.getItemId());
			return true;
		case SystemUtil.GAME_ELEMENT_TRAPHOLE:
			cmv.setElementType(item.getItemId());
			return true;
		case SystemUtil.GAME_ELEMENT_DESTINYHOLE:
			cmv.setElementType(item.getItemId());
			return true;
		case SystemUtil.GAME_ELEMENT_GREENBALL:
			cmv.setElementType(item.getItemId());
			return true;
		case SystemUtil.GAME_ELEMENT_REVOKE:
			cmv.removeElementRecently();
			return true;
		case SystemUtil.GAME_MAP_SAVE:
			ActivityUtil.saveMapWithName(CreateMapActivity.this,
					cmv.getSaveData());
			return true;
		case SystemUtil.GAME_TRY_PLAY:
			Intent intent = new Intent(CreateMapActivity.this,
					WorldActivity.class);
			intent.putExtra("acdGame",
					DataConvertFactory.praseString(cmv.getSaveData()));
			startActivity(intent);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

}
